use std::ffi::{c_char, CStr, CString};

pub struct CChar;

impl CChar {
    pub fn to_string(s: *const c_char) -> String {
        let c_str = unsafe {
            assert!(!s.is_null());
            CStr::from_ptr(s)
        };

        let r_str = c_str
            .to_str()
            .expect("mkstr could not successfully convert string from foreign code!");
        String::from(r_str)
    }

    pub fn to_response_string(s: String) -> *mut c_char {
        let result = CString::new(s).unwrap();
        result.into_raw()
    }
}
